<?php
class pic extends CI_Controller {
	function index() {
		$this -> pub -> logp('浏览图库','1-2');
		$da = $this -> pub -> get_setting('图库', 'Gallery');
		$this -> load -> view('adminx/pic', $da);
	}

	function get() {
		$this -> pub -> logp('获取图库信息','1-2');
		if ($this -> input -> post('key')) {
			$this -> db -> select('count(*)');
			$this -> db -> like('name', $this -> input -> post('key'));
			$q = $this -> db -> get_where('upfile');
			$ls = $q -> row_array(0);
			$num = $ls['count(*)'];
			$this -> db -> like('name', $this -> input -> post('key'));
		} else {
			$this -> db -> select('count(*)');
			$q = $this -> db -> get_where('upfile');
			$ls = $q -> row_array(0);
			$num = $ls['count(*)'];
		}
		//一共的页数
		$da['num'] = ceil($num / 30);

		$page = is_numeric($this -> input -> post('page')) && $this -> input -> post('page') > 0 ? $this -> input -> post('page') : 1;
		$page = $page > $da['num'] ? $da['num'] : $page;
		$da['page'] = $page;

		$page = ($page - 1) == -1 ? 0 : ($page - 1);

		$this -> db -> limit(30, $page * 30);

		$this -> db -> order_by('upfile_id', 'desc');

		$q = $this -> db -> get_where('upfile');
		$da['content'] = '';
		foreach ($q->result_array() as $v) {
			$da['content'] .= '<tr>';
			$da['content'] .= '<td>' . $v['name'] . '</td>';
			$da['content'] .= '<td><img width="48" src="' . $this -> pub -> oss_dz($v['url'].$v['file']) . '" /></td>';
			$da['content'] .= '<td>' . date('Y-m-d H:i:s', $v['upfile_mktime']) . '</td>';
			$da['content'] .= '</tr>';
		}
		$da['type'] = 1;
		echo json_encode($da);
	}

}
?>